package com.ds.dsfans.shell.controller;

import java.util.List;

import com.ds.dsfans.shell.domain.ShellOrder;
import com.ds.dsfans.shell.service.IShellOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ds.dsfans.common.annotation.Log;
import com.ds.dsfans.common.enums.BusinessType;
import com.ds.dsfans.common.core.controller.BaseController;
import com.ds.dsfans.common.core.domain.AjaxResult;
import com.ds.dsfans.common.utils.poi.ExcelUtil;
import com.ds.dsfans.common.core.page.TableDataInfo;

/**
 * 命令列Controller
 * 
 * @author dsfans
 * @date 2024-07-09
 */
@Controller
@RequestMapping("/shell/order")
public class ShellOrderController extends BaseController
{
    private String prefix = "shell/order";

    @Autowired
    private IShellOrderService shellOrderService;

    @RequiresPermissions("shell:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询命令列列表
     */
    @RequiresPermissions("shell:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShellOrder shellOrder)
    {
        startPage();
        List<ShellOrder> list = shellOrderService.selectShellOrderList(shellOrder);
        return getDataTable(list);
    }

    /**
     * 导出命令列列表
     */
    @RequiresPermissions("shell:order:export")
    @Log(title = "命令列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShellOrder shellOrder)
    {
        List<ShellOrder> list = shellOrderService.selectShellOrderList(shellOrder);
        ExcelUtil<ShellOrder> util = new ExcelUtil<ShellOrder>(ShellOrder.class);
        return util.exportExcel(list, "命令列数据");
    }

    /**
     * 新增命令列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存命令列
     */
    @RequiresPermissions("shell:order:add")
    @Log(title = "命令列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShellOrder shellOrder)
    {
        return toAjax(shellOrderService.insertShellOrder(shellOrder));
    }

    /**
     * 修改命令列
     */
    @RequiresPermissions("shell:order:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShellOrder shellOrder = shellOrderService.selectShellOrderById(id);
        mmap.put("shellOrder", shellOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存命令列
     */
    @RequiresPermissions("shell:order:edit")
    @Log(title = "命令列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShellOrder shellOrder)
    {
        return toAjax(shellOrderService.updateShellOrder(shellOrder));
    }

    /**
     * 删除命令列
     */
    @RequiresPermissions("shell:order:remove")
    @Log(title = "命令列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shellOrderService.deleteShellOrderByIds(ids));
    }
}
